package com.ruoyi.web.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.departure.domain.Departure;
import com.ruoyi.departure.service.IDepartureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车次Controller
 * 
 * @author qingshi
 * @date 2021-06-13
 */
@RestController
@RequestMapping("/departureManage/departure")
public class DepartureController extends BaseController
{
    @Autowired
    private IDepartureService departureService;

    /**
     * 查询车次列表
     */
    @PreAuthorize("@ss.hasPermi('departureManage:departure:list')")
    @GetMapping("/list")
    public TableDataInfo list(Departure departure)
    {
        startPage();
        List<Departure> list = departureService.selectDepartureList(departure);
        return getDataTable(list);
    }

    /**
     * 导出车次列表
     */
    @PreAuthorize("@ss.hasPermi('departureManage:departure:export')")
    @Log(title = "车次", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Departure departure)
    {
        List<Departure> list = departureService.selectDepartureList(departure);
        ExcelUtil<Departure> util = new ExcelUtil<Departure>(Departure.class);
        return util.exportExcel(list, "车次数据");
    }

    /**
     * 获取车次详细信息
     */
    @PreAuthorize("@ss.hasPermi('departureManage:departure:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(departureService.selectDepartureById(id));
    }

    /**
     * 新增车次
     */
    @PreAuthorize("@ss.hasPermi('departureManage:departure:add')")
    @Log(title = "车次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Departure departure)
    {
        return toAjax(departureService.insertDeparture(departure));
    }

    /**
     * 修改车次
     */
    @PreAuthorize("@ss.hasPermi('departureManage:departure:edit')")
    @Log(title = "车次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Departure departure)
    {
        return toAjax(departureService.updateDeparture(departure));
    }

    /**
     * 删除车次
     */
    @PreAuthorize("@ss.hasPermi('departureManage:departure:remove')")
    @Log(title = "车次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(departureService.deleteDepartureByIds(ids));
    }
}
